# -*- coding: utf-8 -*-
# @Author	: brotherbaby
# @Date		: 2022-08-16 10:38:21
# @Last Modified by:   brotherbaby
# @Last Modified time: 2022-08-16 10:38:21
# Thanks for your comments!

import json
import logging

from flask_cors import CORS
from gevent import pywsgi

from src.config import CONF
from src.tornadoweb_app import app

logger = logging.getLogger(__name__)


@app.route("/healthz", methods=["GET"])
def health_check():
    resp = {"code": 0, "message": "success"}
    return json.dumps(resp)


import src.api.biz
import src.api.user_assignment
import src.api.sms
import src.api.statistics


def initialize_web_app():
    CORS(app, methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"], supports_credentials=True)
    logger.info(f"initialized web app: {CONF.api.get('port', 8080)}")
    # app.run(host=CONF.api.get('host', '0.0.0.0'), port=CONF.api.get('port', '8080'))
    api_server = pywsgi.WSGIServer((CONF.api.get('host', '0.0.0.0'), CONF.api.get('port', 8080)), app)
    api_server.serve_forever()
